package com.wangwei.spring.rabbit;

import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @RabbitListener 可以用在类上面，当使用在类上面的时候，需要配合@RabbitHandler一起使用，
 * @RabbitHandler 标注在方法上面,表示当有收到消息的时候，就交给带有@RabbitHandler的方法处理，具体找哪个方法处理，需要根据MessageConverter转换后的java对象
 *
 *  @RabbitListener 注解的containerFactory可以指定一个RabbitListenerContainerFactory的bean，默认找名字为rabbitListenerContainerFactory的bean
 * Created by wangwei on 2019/10/16 0016.
 */
@Component
@RabbitListener(queues = {"sms"},containerFactory = "rabbitListenerContainerFactory2")
public class SimpleMessageHandler4Class {
    @RabbitHandler
    public void process(byte[] body){
        System.out.println("------------收到消息(byte[])---------");
        System.out.println(new String(body));
    }
    @RabbitHandler
    public void process(String body){
        System.out.println("------------收到消息(String)---------");
        System.out.println(new String(body));
    }
    @RabbitHandler
    public void process(Body body){
        System.out.println("------------收到消息(Body)---------");
        System.out.println(body);
    }
}
